<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*,java.io.*, java.sql.*, dbAccess.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.text.SimpleDateFormat"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>List of Appointments</title>
<link rel="stylesheet" type="text/css" href="css_files/style.css" />
<script type="text/javascript">
function changeNumberofDays(code)
{
	var mylist;
	if (code == "1")
	{
		mylist = document.forms["frmSearchByRange"].cmbStartMonth;
	}
	else
	{
		mylist = document.forms["frmSearchByRange"].cmbEndMonth;
	}
	var month = mylist.selectedIndex;
	if ((month == 0) || (month == 2) || (month == 4) || (month == 6) || (month == 7) || (month == 9) || (month == 11))
	{
		var days;
		if (code == 1)
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 31; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
	else if (month == 1)
	{
		var days;
		if (code == 1)
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 28; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
	else
	{
		var days;
		if (code == 1)
		{
			days = document.forms["frmSearchByRange"].cmbStartDate;
		}
		else
		{
			days = document.forms["frmSearchByRange"].cmbEndDate;
		}
		days.options.length = 0;
		var i = 1;
		for (i = 1; i <= 30; i++)
		{
			var opt = document.createElement("option");
			days.options.add(opt);
			opt.text = i;
			opt.value = i;
		}
	}
}
</script>
</head>
<body>
<%
	DbAccess access = new DbAccess();
	String query = "select DocId from tbl_doctor where EmailAddress = '" + session.getAttribute("EmailAddress").toString() + "' ";
	query += "and IsDeleted = 0";
		
	String result = access.ExecuteScalar(access.connect(), query);
	int docId = Integer.parseInt(result);
	session.setAttribute("docId",docId);
%>

<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="178" height="125" valign="top"><img src="images/caduceus.gif" alt="" name="LogoLeft" width="150" height="125" id="LogoLeft" style="background-color: #0033FF" /></td>
    <td width="616" align="center" valign="middle"><h1 align="center">CADUCEUS HOSPITAL </h1></td>
    <td width="231" valign="top"><img src="images/hospital.jpg" alt="" name="LogoRight" width="180" height="119" id="LogoRight" style="background-color: #0033FF" /></td>
  </tr>
  <tr>
    <td height="19" colspan="2" valign="top">Welcome Dr.<%=session.getAttribute("Name")%>&nbsp;<%=new java.util.Date() %></td>	
 	<td><a href="home.jsp" title="Logout">Logout</a></td>
  </tr>
</table>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  
  <tr>
        <td width="189" valign="top">
    	<form name="frmSearchByRange" method="post" action="doc2appt.jsp">
    	<table>
    		<tr>
    			<td>
    				<strong>Search For Appointments:</strong>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				<p align="center"><strong>Start Date Range </strong></p>
                 <p align="center"><strong>Year</strong> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       <select name="cmbStartYear" id="cmbStartYear">
                       <option>2009</option>
                       </select>
                                </p>
                 <p align="center"><strong>Month</strong>&nbsp;&nbsp;&nbsp;
                       <select name="cmbStartMonth" id="cmbStartMonth" onchange="changeNumberofDays('1')">
                         <option>January</option>
                         <option>February</option>
                         <option>March</option>
                         <option>April</option>
                         <option>May</option>
                         <option>June</option>
                         <option>July</option>
                         <option>August</option>
                         <option>September</option>
                         <option>October</option>
                         <option>November</option>
                         <option>December</option>
                       </select>
                   </p>
                 <p align="center"><strong>Date</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       <select name="cmbStartDate" id="cmbStartDate">
                         <option>1</option>
                         <option>2</option>
                         <option>3</option>
                         <option>4</option>
                         <option>5</option>
                         <option>6</option>
                         <option>7</option>
                         <option>8</option>
                         <option>9</option>
                         <option>10</option>
                         <option>11</option>
                         <option>12</option>
                         <option>13</option>
                         <option>14</option>
                         <option>15</option>
                         <option>16</option>
                         <option>17</option>
                         <option>18</option>
                         <option>19</option>
                         <option>20</option>
                         <option>21</option>
                         <option>22</option>
                         <option>23</option>
                         <option>24</option>
                         <option>25</option>
                         <option>26</option>
                         <option>27</option>
                         <option>28</option>
                         <option>29</option>
                         <option>30</option>
                         <option>31</option>
                       </select>
                   </p>
                 <p align="center">&nbsp;</p>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				<p align="center">End Date Range </p>
                 <p align="center">Year &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       <select name="cmbEndYear" id="cmbEndYear">
                         <option>2009</option>
                                            </select>
                                </p>
                 <p align="center">Month &nbsp;&nbsp;&nbsp;
                   <select name="cmbEndMonth" id="select2" onChange="changeNumberofDays('2')">
                     <option>January</option>
                     <option>February</option>
                     <option>March</option>
                     <option>April</option>
                     <option>May</option>
                     <option>June</option>
                     <option>July</option>
                     <option>August</option>
                     <option>September</option>
                     <option>October</option>
                     <option>November</option>
                     <option>December</option>
                   </select>
                 </p>
                 <p align="center">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                       <select name="cmbEndDate" id="select3">
                         <option>1</option>
                         <option>2</option>
                         <option>3</option>
                         <option>4</option>
                         <option>5</option>
                         <option>6</option>
                         <option>7</option>
                         <option>8</option>
                         <option>9</option>
                         <option>10</option>
                         <option>11</option>
                         <option>12</option>
                         <option>13</option>
                         <option>14</option>
                         <option>15</option>
                         <option>16</option>
                         <option>17</option>
                         <option>18</option>
                         <option>19</option>
                         <option>20</option>
                         <option>21</option>
                         <option>22</option>
                         <option>23</option>
                         <option>24</option>
                         <option>25</option>
                         <option>26</option>
                         <option>27</option>
                         <option>28</option>
                         <option>29</option>
                         <option>30</option>
                         <option>31</option>
                       </select>
                   </p>
               <p align="center">&nbsp;</p>
    			</td>
    		</tr>
    		<tr>
    			<td>
    				 <input name="cmdSearch" type="submit" id="cmdSearch" value="Search">
    			</td>
    		</tr>
    	</table>
    	</form>
    	
    	</td>
    <td width="619" rowspan="2" valign="top"><strong>List of Appointments for <%="Dr. " + session.getAttribute("Name")%></strong>
    <table width="100%" height="34" border="1" align="left">
        <thead>
        <tr>
          <td><strong>Appointment Id</strong></td>
          <td><strong>Patient Name</strong></td>
          <td><strong>Date</strong></td>
          <td><strong>Start Time</strong></td>
          <td><strong>End Time</strong></td>
          <td><strong>Building</strong></td>
          <td><strong>Room Number</strong></td>
          <td><strong>Visitation Record(s)</strong></td>
        </tr>
        </thead>
        <%
        Login lgn = new Login();
    	ResultSet rs;
		int appointmentId = 0;
		String patientName = "unknown";
		java.sql.Time startTime = Time.valueOf("00:00:00");
		java.sql.Time endTime = Time.valueOf("00:00:00");
		String building = "unknown";
		String roomNum = "unknown";
		java.sql.Date apptDate;
		int visitId = 0;
		
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		
		String startYear = request.getParameter("cmbStartYear").toString();
		String startMonth = request.getParameter("cmbStartMonth").toString();
		String startDay = request.getParameter("cmbStartDate").toString();
		String startDate = startYear + "-" + Login.monthFormat(startMonth) + "-" + startDay;

		
		String endYear = request.getParameter("cmbEndYear").toString();
		String endMonth = request.getParameter("cmbEndMonth").toString();
		String endDay = request.getParameter("cmbEndDate").toString();
		String endDate = endYear + "-" + Login.monthFormat(endMonth) + "-" + endDay;
		
		java.sql.Date sDateSQL = java.sql.Date.valueOf(startDate);	
		java.sql.Date eDateSQL = java.sql.Date.valueOf(endDate);
		rs = lgn.getAppointmentList((Integer)session.getAttribute("docId") ,"Doctor",sDateSQL,eDateSQL);
		
		while (rs.next())
		{	
			appointmentId = rs.getInt("tbl_appointment.Appointmentid");
			patientName = rs.getString("patientFirstName") + " " + rs.getString("patientLastName");
			apptDate = rs.getDate("tbl_appointment.Date");
			startTime = rs.getTime("tbl_appointment.StartTime");
			endTime = rs.getTime("tbl_appointment.EndTime");
			building = rs.getString("tbl_appointment.Building");
			roomNum = rs.getString("tbl_appointment.Room");
			visitId = rs.getInt("tbl_visit.VisitId");
        %>
        
        <tbody>
        	<tr>
        		<td>
        			<%=appointmentId%>
        		</td>
        		<td>
        			<%=patientName%>
        		</td>
        		<td>
        			<%=apptDate%>
        		</td>
        		<td>
        			<%=startTime%>
        		</td>
        		<td>
        			<%=endTime%>
        		</td>
        		<td>
        			<%=building%>
        		</td>
        		<td>
        			<%=roomNum%>
        		</td>
        		<td>
        			<%
        				if (visitId != 0)
        				{
        			%>
        				<a href = "patientVisit.jsp?vId=<%=visitId%>&callerId=doc2appt">Visitation Record</a>
        					<%
        				}
        				else 
        				{		
        			%>
        				N/A.
        					
        			<%}
        			%>
        				
        			
        		</td>
        	</tr>
        </tbody>
        <%
		}
        %>
        
      </table>      
      <p>&nbsp;</p>    </td>
    <td width="251" height="153" valign="top"><p align="center"><strong> Person Lookup</strong></p>
                  
      <form id="frmSearch" name="frmSearch" method="post" action="searchByDoc.jsp">
         <p> 
        <input name="personType" type="radio" value="Patient" checked>
        Patient&nbsp;
        <input name="personType" type="radio" value="Doctor">
        Doctor&nbsp;
        <input name="personType" type="radio" value="Staff">
        Staff </p>
        <p>
        &nbsp;&nbsp;Search for 
          <input type="text" name="TextField1" id="TextField1" />
          <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <select name="SearchField1" id="SearchField1">
                    <option selected="selected">FirstName</option>
                    <option>LastName</option>
                    <option>Address</option>
                    <option>Gender</option>
            		<option>PhoneNumber</option>
           			<option>EmailAddress</option>
            		<option>DateOfBirth</option>
            		<option>Id</option>
          </select>
      </p>
        <p class="style5">&nbsp;<em>AND</em></p>
        <p>&nbsp;&nbsp;Search for
          <input type="text" name="TextField2" id="TextField2" />
          <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <select name="SearchField2" id="SearchField2">
                    <option selected="selected">FirstName</option>
                    <option>LastName</option>
                    <option>Address</option>
                    <option>Gender</option>
            		<option>PhoneNumber</option>
           			<option>EmailAddress</option>
            		<option>DateOfBirth</option>
            		<option>Id</option>
          </select>
        </p>
        <p>&nbsp;<em class="style5">AND</em></p>
        <p>&nbsp;&nbsp;Search for
          <input type="text" name="TextField3" id="TextField3" />
            <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <select name="SearchField3" id="SearchField3">
                    <option selected="selected">FirstName</option>
                    <option>LastName</option>
                    <option>Address</option>
                    <option>Gender</option>
            		<option>PhoneNumber</option>
           			<option>EmailAddress</option>
            		<option>DateOfBirth</option>
            		<option>Id</option>
  </select>
        </p>
        <p align="center">
          <input type="submit" name="Search1" id="Search1" value="Search" />
        </p>
      </form>      </td>
  </tr>
  
  <tr>
    <td valign="top" class="style2"><p align="center"><strong>Quicklinks</strong></p>
    <p><a href="patientListforDoc.jsp">View List of Patients</a></p>
    <p><a href="editDoctorInfoByDoc.jsp">Change My Personal Information</a></p>
    <p><a href="http://www.webmd.com">WebMD</a></p>
    <p><a href="docStaffAccess.jsp?docId=<%=session.getAttribute("docId")%>">Grant Staff Access</a></p>
	<p><a href="docStaffAccessRemove.jsp?docId=<%=session.getAttribute("docId")%>">Remove Staff Access</a></p>
	<p><a href="docPatientAccess.jsp?docId=<%=session.getAttribute("docId")%>">Grant Doctor Access</a></p>
	<p><a href="docPatientAccessRemove.jsp?docId=<%=session.getAttribute("docId")%>">Remove Doctor Access</a></p>
	<p><a href="doctorHome.jsp">Back to Homepage </a></p>
	</td>
	<td>
    <form id="frmSearchVisit" name="frmSearchVisit" method="post" action="visitSearchResults.jsp">
         <p> <strong>
         Visitation Search
          </strong></p>
        <p>
        &nbsp;&nbsp;Search for 
          <input type="text" name="txtVisit1" id="txtVisit1" />
          <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <select name="SearchVisit1" id="SearchVisit1">
            <option selected="selected">Diagnosis</option>
            <option>VisitId</option>
            <option>AppointmentId</option>
            <option>Prescription</option>
            <option>Dosage</option>
            <option>Comments</option>
            </select>
      </p>
        <p class="style5">&nbsp;<em>AND</em></p>
        <p>&nbsp;&nbsp;Search for
          <input type="text" name="txtVisit2" id="txtVisit2" />
          <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <select name="SearchVisit2" id="SearchVisit2">
                        <option selected="selected">Diagnosis</option>
            <option>VisitId</option>
            <option>AppointmentId</option>
            <option>Prescription</option>
            <option>Dosage</option>
            <option>Comments</option>
            </select>
        </p>
        <p>&nbsp;<em>AND</em></p>
        <p>&nbsp;&nbsp;Search for
          <input type="text" name="txtVisit3" id="txtVisit" />
            <br />
          &nbsp;&nbsp;in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  <select name="SearchVisit3" id="SearchVisit3">
      <option selected="selected">Diagnosis</option>
            <option>VisitId</option>
            <option>AppointmentId</option>
            <option>Prescription</option>
            <option>Dosage</option>
            <option>Comments</option>
            </select>
        </p>
        <p align="center">
          <input type="submit" name="SearchVisit" id="SearchVisit" value="Search" />
        </p>
      </form>      
    	
    </td>
  </tr>
</table>
</body>
</html>